﻿using System.Diagnostics.Contracts;
using System.IO;

namespace DaveSexton.Labs
{
	internal sealed class FileObject : FileSystemInfo, IFile
	{
		private readonly FileInfo file;

#if SILVERLIGHT
		[System.Security.SecuritySafeCritical]
		public FileObject()
		{
			throw new System.NotSupportedException();
		}
#endif

		public FileObject(string fileName)
			: this(new FileInfo(fileName))
		{
			Contract.Requires(fileName != null);
		}

		public FileObject(FileInfo file)
		{
			Contract.Requires(file != null);

			this.file = file;
		}

		[ContractInvariantMethod]
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Required for code contracts.")]
		private void ObjectInvariant()
		{
			Contract.Invariant(file != null);
		}

		public override bool Exists
		{
			get
			{
				return file.Exists;
			}
		}

		public override string FullName
		{
			get
			{
				return file.FullName;
			}
		}

		public override string Name
		{
			get
			{
				return file.Name;
			}
		}

		public override void Delete()
		{
			file.Delete();
		}

		public override string ToString()
		{
			return file.ToString();
		}
	}
}